#!/bin/bash

##### 变量定义与使用

echo "##### 变量定义与使用"
var1=kusosun
var2='kusosun'
var3="kusosun"

echo var1
echo 'var1'
echo "${var1}" #推荐使用
echo $var1

##### 由命令生成变量

echo "##### 由命令生成变量"
var1=`ls -a`
var2="$(ls -a)" #推荐使用

echo "${var2}"
echo "${var1}"

##### 常量

echo "##### 常量"
var1="kusoash"
echo "${var1}"
readonly var1
# var1="kusosun"
# echo "${var1}" #line 27: var1: readonly variable

##### 删除变量

echo "##### 删除变量"
var3="kusosun"
echo "${var3}"
unset var3

echo "var3 is (${var3})"

##### 变量作用域

echo "##### 变量作用域"
function test(){
	var4="sunkuso"
	echo "var4 -> ${var4}"
	local var5="localkuso"
}

test

echo "var4 -> ${var4}"
echo "var5 -> ${var5}"

export tmp=123
echo "tmp -> ${tmp}"
ls -a
sh ./1-1-child.sh

##### 特殊变量
echo "##### 特殊变量"

function method(){
	echo "$0"
	echo "$1"
	echo "$2"
	echo "$*"
	echo "${#1}"
	echo "$@"
	echo "$$"
}
method "kuso" "sun"

echo "$?"

